package com.jnshu.tools.resultUtils;

/**
 * @ClassName RUtil
 * @Descrintion
 * @Author bd
 * @Date 2019/8/3 15:34
 * @Version 1.0
 **/
public class RUtil {
    /**
     * @Author bd
     * @Description 传输成功的时候用枚举返回信息
     * @Date 10:41 2019/8/3
     * @Param  ok
     * @return
     **/
    public static ResultBean ok(Object data) {
        return new ResultBean(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    public static ResultBean ok() {
        return new ResultBean(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage());
    }


    /**
     * 成功使用枚举返回信息，PageBean默认一页十条数据
     *
     * @param totalCount
     * @param data
     * @return
     */
    public static PageBean okDefault(long totalCount, Object data,int pageNum,int pageSize) {
        return new PageBean(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), pageNum, pageSize, totalCount, data);
    }


    /**
     * @Author bd
     * @Description传输失败的时候用枚举返回信息
     * @Date 10:53 2019/8/3
     * @Param
     * @return com.jnshu.tools.resultUtils.ResultBean
     **/
    public static ResultBean error(ResultEnum error) {
        return new ResultBean(error.getCode(), error.getMessage(),null);
    }

    /**
     * 使用枚举列举错误类型--PageBean
     * @param error
     * @return
     */
    public static PageBean errorPage(ResultEnum error) {
        return new PageBean(error.getCode(),error.getMessage(), null, 0, null);
    }

    public static ResultBean error(Integer code, String msg) {
        return new ResultBean(code, msg);
    }

    public static ResultBean error(){
        return new ResultBean(ResultEnum.FAILURE.getCode(),ResultEnum.FAILURE.getMessage());
    }

}



